﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Xml.Serialization;
using System.Text;
using System.Diagnostics;
using AppFx.BizTalk.Serialization;

namespace AppFx.BizTalk.Tests.Serialization
{
    /// <summary>
    /// Contains tests for the Serialization helper
    /// </summary>
    [TestClass]
    public class GenericXmlSerializerTests
    {
        /// <summary>
        /// The namespace for the tests
        /// </summary>
        public const string Namespace = "urn:SerializationHelperTests";
        /// <summary>
        /// Tests the serialize method
        /// </summary>
        [TestMethod]
        public void GreenPathTest()
        {
            const string Expected = "Test";

            SerializationTestableType typeToTest = new SerializationTestableType();
            typeToTest.TestProperty = Expected;

            GenericXmlSerializer<SerializationTestableType> helper = new GenericXmlSerializer<SerializationTestableType>();
            string tempXml = helper.SerializeToString(typeToTest);
            Trace.WriteLine(tempXml);
            SerializationTestableType newType = helper.Deserialize(tempXml, Namespace);

            Assert.IsTrue(newType.TestProperty == Expected, "The new deserialized type was not as expected");
        }        
    }
    /// <summary>
    /// A serializable object for testing the message helper
    /// </summary>
    [XmlRoot("SerializationTestableType", Namespace = GenericXmlSerializerTests.Namespace)]
    public class SerializationTestableType
    {
        private string _TestProperty;
        /// <summary>
        /// Exposes the test property
        /// </summary>
        public string TestProperty
        {
            get { return _TestProperty; }
            set { _TestProperty = value; }
        }
    }
}


